
function isMoveX(students,index){
    if (students[index][0] === 0){
        return false;
    }
    let flag = true;
    for (let i = 0; i < students.length; i++) {
        if (students[i][0] === students[index][0] - 1 && students[i][1] === students[index][1]){
            flag = false;
            index =  i;
            break;
        }
    }
    if (flag){
        return true;
    }else {
        return isMoveX(students,index)
    }

}

function solution(){
    let students = [[3,4],[2,3]];
    let time = 0;
    let n = students.length;
    while(1){
        for (let i = 0; i < n; i++) {
            if (students[i][0] === 0 &&  students[i][1] !== 0){
                students[i][1]--;
            }
            if (students[i][0] !== 0 && isMoveX(students,i)){
                students[i][0]--;
            }
        }
        time++;
        if (students.every(item => item[0] === 0 && item[1] === 0)){
            break;
        }
    }
    console.log(time)
}
solution()
console.log(isMoveX([[3,4],[2,3]],0));